<template>
    <UnitBaseInfo :opType="opType" :opUnitInfo="opUnitInfo" v-if="(opType==1||opType==3)&&opUnitInfo.id"/>

    <el-form ref="unitRef" :model="form" label-width="96px" :disabled="opType==2||opType==3">
        <el-card class="w-full mt-[10px]">
            <CardHead> 科技部统计信息</CardHead>
            <el-row :gutter="20">
                <el-col :span="1"></el-col>
                <el-col :span="22">
                    <el-form-item label="平台简介" style="align-items: center;">
                        <editor v-model="form.platformSummary" :placeholder="(opType==2||opType==3)?'':'请输入内容'" :min-height="192" :readOnly="opType==2||opType==3"/>
                    </el-form-item>
                </el-col>
                <el-col :span="1"></el-col>
            </el-row>
        </el-card>
    </el-form>
</template>

<script setup>
import cloneDeep from 'lodash/cloneDeep';  
import useUserStore from '@/store/modules/user';
import CardHead from "./CardHead.vue";
import UnitBaseInfo from "./UnitBaseInfo.vue";
import { listUnit, getUnit, delUnit, addUnit, editPlatformSummary, getCategoryData } from "@/api/research/unit";

const { proxy } = getCurrentInstance();

const emit = defineEmits(['refreshUnitList']);  
const props = defineProps({
  opType: {  
    type: Number,
    required: true,
    default: 0      // 默认值  0:add 1:edit 2:check 3:view
  },
  opUnitInfo: {  
    type: Object,
    required: false,
  }
}) 

const data = reactive({
  form: {},
});

const { form } = toRefs(data);

onMounted(() => {
    //reset();
    switch (props.opType) {
        case 0:
            break;
        case 1:
        case 2:
        case 3:
            //form.value = cloneDeep(props.opUnitInfo);
            form.value.id = props.opUnitInfo.id;
            form.value.platformSummary = props.opUnitInfo.platformSummary;
            form.value.checkStatus = props.opUnitInfo.checkStatus;
            break;
        default:
            proxy.$modal.msgError("未知操作");
            return;
    }
})

//保存
function save() {
    proxy.$refs["unitRef"].validate(valid => {
        if (valid) {
            if (props.opType == 1 && form.value.id != null) {
                editPlatformSummary(form.value).then(response => {
                    proxy.$modal.msgSuccess("修改成功");
                    emit('refreshUnitList', true);
                });
            }
        }
    });
}

//保存并提交
function saveAndSubmit() {
  //
}

//保存并通过
function saveAndPass() {
  //
}

//关闭
function cancel() {
    //reset();
    proxy.resetForm("unitRef");
}

defineExpose({save,saveAndSubmit,saveAndPass,cancel});
</script>

<style scoped lang="scss">
@import url("../index.scss");
:deep(.editor) {
    width: 100%;
}
</style>